package com.example.Blog.service;

import com.example.Blog.dao.ArticleTypeDao;
import com.example.Blog.model.ArticleType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ArticleTypeService {
    final ArticleTypeDao articleTypeDao;

    public ArticleTypeService(ArticleTypeDao articleTypeDao) {
        this.articleTypeDao = articleTypeDao;
    }

    public ArticleType findByTypeName(String typeName){
        return this.articleTypeDao.findByTypeName(typeName);
    }

    public boolean add(String typeName){
        ArticleType articleType = new ArticleType();
        articleType.setTypeId(new Date().hashCode());
        articleType.setTypeName(typeName);
        this.articleTypeDao.save(articleType);
        this.articleTypeDao.findByTypeName(typeName);
        return true;
    }

    public boolean delete(String typeName){
        this.articleTypeDao.deleteByTypeName(typeName);
        return true;
    }
}
